using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using QLKS.DataLayer.ManagerObjects;
using QLKS.DataLayer.BusinessObjects;
using QLKS.DataLayer.Base;

namespace QLKS.DataLayer.UnitTests
{
	[TestFixture]
    public partial class NhanVienTests : UNuitTestBase
    {
        protected INhanVienManager manager;
		
		public NhanVienTests()
        {
            manager = managerFactory.GetNhanVienManager();
        }
		
		protected NhanVien CreateNewNhanVien()
		{
			NhanVien entity = new NhanVien();
			
			// You may need to maually enter this key if there is a constraint violation.
			entity.Id = "Test Test T";
			
			entity.HoTenNhanVien = "Test Test Test Test Test Test Test Test Test T";
			entity.GioiTinh = true;
			entity.NamSinh = DateTime.Now;
			entity.Cmnd = "Test Test";
			entity.Luong = 8;
			entity.Email = "Test Test Test Test T";
			entity.UserLogin = "Test Test Test T";
			entity.Password = "Test Test Test Test Test Test";
			entity.IsActive = true;
			entity.HomePhone = "Test Tes";
			entity.CellPhone = "Test Tes";
			entity.Fax = "Test Test Test T";
			entity.ChucVu = "Te";
			entity.DiaChi = "Test Test Test Test Tes";
			entity.City = "Test Test Test Test T";
			entity.Country = "Test Test Test Test Test Te";
			entity.ZipCode = "T";
			
			return entity;
		}
		protected NhanVien GetFirstNhanVien()
        {
            IList<NhanVien> entityList = manager.GetAll(1);
            if (entityList.Count == 0)
                Assert.Fail("All tables must have at least one row for unit tests to succeed.");
            return entityList[0];
        }
		
		[Test]
        public void Create()
        {
            try
            {
				NhanVien entity = CreateNewNhanVien();
				
                object result = manager.Save(entity);

                Assert.IsNotNull(result);
            }
            catch(Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
        [Test]
        public void Read()
        {
            try
            {
                NhanVien entityA = CreateNewNhanVien();
				manager.Save(entityA);

                NhanVien entityB = manager.GetById(entityA.Id);

                Assert.AreEqual(entityA, entityB);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
		[Test]
		public void Update()
        {
            try
            {
                NhanVien entityA = GetFirstNhanVien();
				
				entityA.HoTenNhanVien = "Test Test Test Test Test Test Test Test ";
				
				manager.Update(entityA);

                NhanVien entityB = manager.GetById(entityA.Id);

                Assert.AreEqual(entityA.HoTenNhanVien, entityB.HoTenNhanVien);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
        [Test]
        public void Delete()
        {
            try
            {
                NhanVien entity = GetFirstNhanVien();
				
                manager.Delete(entity);

                entity = manager.GetById(entity.Id);
                Assert.IsNull(entity);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
	}
}

